﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MuaChung.Models.PagingModel>" %>
<%if (ViewData["result"] == "NoItem")
  {%>
      
  <%}
  else
  {%>

<%if (Model.currentPage == 1)
  {%>
      First Previous
  <%}
  else
  {%>
      <a href="<%:Model.url %>currentPage=1">First</a>
      <a href="<%:Model.url %>currentPage=<%:Model.currentPage-1%>">Previous</a>
  <%}
  int start = 2;
  if (Model.currentPage > 4)
  {%>
      <a href="<%:Model.url %>currentPage=1">1</a>...
      
   <%start = Model.currentPage - 2;
  }
  else if (Model.currentPage == 1)
  { %>
        <a class="currentPage" href="<%:Model.url %>currentPage=1">1</a>
   <%}
  else
  { %>
        <a href="<%:Model.url %>currentPage=1">1</a>
   <%} %>
<%for (int i = start; i <= Model.currentPage; i++)
  {
      if (i == Model.currentPage)
      {%>
          <a class="currentPage" href="<%:Model.url %>currentPage=<%:i %>"><%:i%></a>
      <%}
      else
      {%>
          <a href="<%:Model.url %>currentPage=<%:i %>"><%:i%></a>          
      <%}
  }
  %>
  <%if (Model.totalPage - Model.currentPage > 4)
    {%>
        <%for (int i = Model.currentPage + 1; i <= Model.currentPage + 2; i++)
          {%>
                <a href="<%:Model.url %>currentPage=<%:i %>"><%:i%></a>
        <%}%>
        ...<a href="<%:Model.url %>currentPage=<%:Model.totalPage %>"><%:Model.totalPage%></a>
    <%}
    else if (Model.currentPage < Model.totalPage)
    {%>
        <%for (int i = Model.currentPage + 1; i <= Model.totalPage; i++)
          {%>
                <a href="<%:Model.url %>currentPage=<%:i %>"><%:i%></a>
        <%}%>
    <%} %>
  <%if (Model.currentPage == Model.totalPage)
    {%>
      Next Last
  <%}
    else
    {%>      
      <a href="<%:Model.url %>currentPage=<%:Model.currentPage+1%>">Next</a>
      <a href="<%:Model.url %>currentPage=<%:Model.totalPage %>">Last</a>
  <%}
  }%>
